import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.wsdl.Part;
import javax.xml.namespace.QName;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.log4j.Logger;
import org.apache.xerces.dom.ElementNSImpl;
import org.eclipse.bpel.model.Activity;
import org.eclipse.bpel.model.ModelPackage;
//import org.eclipse.bpel.model.BPELPlugin;
import org.eclipse.bpel.model.ModelPackage;
import org.eclipse.bpel.model.PartnerLink;
import org.eclipse.bpel.model.PartnerLinks;
import org.eclipse.bpel.model.Variable;
import org.eclipse.bpel.model.Variables;
import org.eclipse.bpel.model.adapters.AdapterRegistry;
import org.eclipse.bpel.model.adapters.BasicBPELAdapterFactory;
//import org.eclipse.bpel.model.impl.ModelPackageImpl;
import org.eclipse.bpel.model.resource.BPELReader;
import org.eclipse.bpel.model.resource.BPELResource;
import org.eclipse.bpel.model.resource.BPELResourceFactoryImpl;
import org.eclipse.bpel.model.resource.BPELResourceImpl;
import org.eclipse.bpel.model.resource.BPELResourceSetImpl;
import org.eclipse.bpel.model.util.BPELSwitch;
import org.eclipse.bpel.model.util.BPELUtils;
import org.eclipse.bpel.model.util.ModelAdapterFactory;
import org.eclipse.bpel.model.util.WSDLUtil;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.Message;
import org.eclipse.wst.wsdl.Output;
import org.eclipse.wst.wsdl.PartnerLinkType;
import org.eclipse.wst.wsdl.PortType;
import org.eclipse.wst.wsdl.Role;
import org.eclipse.wst.wsdl.WSDLFactory;
import org.eclipse.wst.wsdl.WSDLPackage;
import org.eclipse.wst.wsdl.WSDLPlugin;
import org.eclipse.wst.wsdl.internal.impl.MessageImpl;
import org.eclipse.wst.wsdl.internal.impl.OperationImpl;
import org.eclipse.wst.wsdl.internal.impl.PartnerLinkTypeImpl;
import org.eclipse.wst.wsdl.internal.impl.PortTypeImpl;
import org.eclipse.wst.wsdl.internal.impl.ServiceImpl;
import org.eclipse.wst.wsdl.internal.impl.UnknownExtensibilityElementImpl;
import org.eclipse.wst.wsdl.internal.impl.WSDLPackageImpl;
import org.eclipse.wst.wsdl.internal.impl.wsdl4j.WSDLFactoryImpl;
import org.eclipse.wst.wsdl.internal.util.WSDLAdapterFactory;
import org.eclipse.wst.wsdl.internal.util.WSDLResourceFactoryImpl;
import org.eclipse.wst.wsdl.util.WSDLResourceImpl;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDPackage;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
import org.eclipse.xsd.XSDTypeDefinition;
import org.eclipse.xsd.impl.XSDElementDeclarationImpl;
import org.eclipse.xsd.impl.XSDParticleImpl;
import org.eclipse.xsd.util.XSDAdapterFactory;
import org.eclipse.xsd.util.XSDResourceFactoryImpl;

/**
 * TODO: compensation handler wird ignoriert!
 */
public class Main {
	
	private static TransformerFactory transfac = null;
	
	private static Transformer trans = null;

	/**
	 * Reads a bpel file and creates a EMF process object from it.
	 * 
	 * The employed BPELReader can only read BPEL 2.0 processes. It does not
	 * support BPEL 1.1.
	 * 
	 * You have to set up import XML elements in the BPEL and WSDL documents
	 * for the reader to be able to import the documents. The documents have
	 * all to be placed inside the same folder.
	 * 
	 * Example: If your bpel file uses the bam.wsdl web service, put your
	 * bpel file and the bam.wsdl file into the same folder. Insert an import
	 * inside the bpel file, so that the reader is able to resolve the bam
	 * web service.
	 * 
	 * <!-- namespace is targetnamespace of the wsdl file that is referenced -->
     * <import 
     *  location="bam.wsdl" 
     *  namespace="http://bamspace_MasterOfTheUniverse_NAMESPACEXML_BOINK_POW_2009/" 
     *  importType="http://schemas.xmlsoap.org/wsdl/">
     * </import>
     * 
     * If your wsdl files do not define XSD schemas inline but in an extra
     * file, then your schema xml element inside the wsdl files has to define
     * an import:
     * 
     * <types>
	 *   <schema xmlns="http://www.w3.org/2001/XMLSchema">
	 *     <import namespace="http://ong/back/MasterOfTheUniverse/Girl/Poff/BANG/2009" 
	 *             schemaLocation="bam.xsd" />
	 *   </schema>
	 * </types>
	 * 
	 * You have to get your namespace EXACTLY right between the referencing
	 * statement and the importing file. Otherwise the superpedantic BPELReader
	 * will not import anything!
	 * 
	 * @param args
	 * @throws IOException
	 * @throws TransformerException 
	 * @throws WSDLException
	 */
	public static void main(String[] args) throws IOException, TransformerException {

		Logger log = Logger.getLogger(Main.class);
		
		// for DOM output
		try {
			// Set up the DOM XML output transformer
			transfac = TransformerFactory.newInstance();
			trans = transfac.newTransformer();
			trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
			trans.setOutputProperty(OutputKeys.INDENT, "yes");
		} catch (TransformerConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		File file = null;
		file = new File("C://temp//RentalProcess.bpel");
//		file = new File("C://temp//loanApproval.bpel"); // loan approval has a lot of links in the flow
//		file = new File("C://temp//OrderProcess//LoanFlowApplication//LoanFlowProject//bpel//LoanFlowProject.bpel");
//		file = new File("C://temp//OrderProcess//bpel//OrderProcess.bpel");
//		file = new File("C://temp//OrderProcess//TestProcessesApplication//SequentialBPELProcess//bpel//SequentialBPELProcess.bpel");
//		file = new File("C://Dokumente und Einstellungen//admin//workspace//BusinessImpactAnalysis//testdata//processes//CarRentalAndSaleApp//RentalCarInsurance//RentalSystemPort.wsdl");
		
		log.trace("Loading: " + file.getName());
		log.trace("If resolution of objects fails, check your import statements in the various files!");
		
		// log.trace("exists: " + file.exists());

		InputStream inputStream = new BufferedInputStream(new FileInputStream(
				file.getAbsolutePath()));

		URI uri = URI.createFileURI(file.getAbsolutePath());

		// File file2 = new File("CustomerDataAccessService.wsdl");
		// // log.trace("exists: " + file2.exists());
		// // InputStream inputStream2 = new BufferedInputStream(new
		// FileInputStream(
		// // file2.getAbsolutePath()));
		// URI uri2 = URI.createFileURI(file2.getAbsolutePath());

		// DO WE REALLY NEED THIS?
		// WSDLPackage.init();
//		ModelPackageImpl.init();
//		ModelPackage.init();
		WSDLPackageImpl.init();

		// Create the Quasi-Eclipse environment ...
		// AdapterRegistry.INSTANCE.registerAdapterFactory( new
		// org.eclipse.bpel.validator.factory.AdapterFactory() );
		AdapterRegistry.INSTANCE.registerAdapterFactory(ModelPackage.eINSTANCE,
				BasicBPELAdapterFactory.INSTANCE);
		
//		ModelAdapterFactory maf = new ModelAdapterFactory();
//		AdapterRegistry.INSTANCE.registerAdapterFactory(ModelPackage.eINSTANCE,
//				maf);

		WSDLAdapterFactory wsdlAdapterFactory = new WSDLAdapterFactory();
		// javax.wsdl.factory.WSDLFactory wsdlAdapterFactory =
		// javax.wsdl.factory.WSDLFactory.newInstance();
		AdapterRegistry.INSTANCE.registerAdapterFactory(WSDLPackage.eINSTANCE,
				wsdlAdapterFactory);
		
		XSDAdapterFactory xsdAdapterFactory = new XSDAdapterFactory();
		AdapterRegistry.INSTANCE.registerAdapterFactory(XSDPackage.eINSTANCE,
				xsdAdapterFactory);
		
		// PartnerlinktypeAdapterFactory plnktypeAdapterFactory = new
		// PartnerlinktypeAdapterFactory();
		// AdapterRegistry.INSTANCE.registerAdapterFactory(WSDLPackage.eINSTANCE,
		// plnktypeAdapterFactory);
		//		
		BPELResourceSetImpl resourceSet = new BPELResourceSetImpl();

		// BPELResourceFactoryImpl bpelResourceFactory = new
		// BPELResourceFactoryImpl();
		// resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*",
		// bpelResourceFactory);
		//		
		// WSDLResourceFactoryImpl wsdlResourceFactory = new
		// WSDLResourceFactoryImpl();
		// resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*",
		// wsdlResourceFactory);

		BPELResourceFactoryImpl bpelResourceFactory = new BPELResourceFactoryImpl();
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
				.put("bpel", bpelResourceFactory);

		WSDLResourceFactoryImpl wsdlResourceFactory = new WSDLResourceFactoryImpl();
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
				.put("wsdl", wsdlResourceFactory);
		
//		XSDResourceFactoryImpl xsdResourceFactoryImpl = new XSDResourceFactoryImpl();
//		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
//			.put("bpel", xsdResourceFactoryImpl);

		// PartnerlinktypeExtensibilityElementFactory plinktypeResourceFactory =
		// new PartnerlinktypeExtensibilityElementFactory();
		// resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("wsdl",
		// plinktypeResourceFactory);

		// PartnerlinktypeFactoryImpl plnktypeFactory =
		// new PartnerlinktypeFactoryImpl();
		// plnktypeFactory.init();
		// resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("wsdl",
		// plnktypeFactory);

		// Resource.Factory resourceFactory =
		// resourceSet.getResourceFactoryRegistry().getFactory(uri, null);
		// log.trace("Using " + resourceFactory.getClass() + " to load " + uri);
		BPELResource resource = (BPELResource) resourceSet.createResource(uri);

		// resourceFactory =
		// resourceSet.getResourceFactoryRegistry().getFactory(uri2, null);
		// log.trace("Using " + resourceFactory.getClass() + " to load " +
		// uri2);
		// WSDLResourceImpl wsdlResource = (WSDLResourceImpl)
		// resourceSet.createResource(uri2);

		// resource.load(null);
		// wsdlResource.load(null);

		// log.trace("ResourceSet manages " + resourceSet.getResources().size()
		// + " resources");

		// BPELResourceFactoryImpl factory = new BPELResourceFactoryImpl();
		// Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*",
		// factory);

		BPELReader reader = new BPELReader();
		reader.read(resource, inputStream);

		org.eclipse.bpel.model.Process p = (org.eclipse.bpel.model.Process) resource
				.getContents().get(0);

		// qName = new QName("http://rentalservices/");
		// BPELUtils.lookup(resource
		// .getContents().get(0), qName, "", WSDLUtil.BPEL_PARTNER_LINK_TYPE);

		dumpProcess(log, p);
		dumpPartnerLinks(log, p);
		dumpVariables(log, p);

		// URIConverter uriConverter = new ExtensibleURIConverterImpl();
		//		
		// Map<?, ?> options = new HashMap<Object, Object>();
		// Map<?, ?> response = new HashMap<Object, Object>();
		//		
		// Map<?, ?> response = options == null ? null : (Map<?,
		// ?>)options.get(URIConverter.OPTION_RESPONSE);
		// if (response == null)
		// {
		// response = new HashMap<Object, Object>();
		// }

		// inputStream = uriConverter.createInputStream(uri, options);

		// BPELPlugin bpelPlugin = BPELPlugin.INSTANCE;

		//		
		//
		// ResourceSet resourceSet = new ResourceSetImpl();
		//		
		// Resource resource = resourceSet.getResource(uri, true);

		// WSDLPlugin.INSTANCE.log("shom test");
		//		
		// WSDLFactoryImpl wsdlFactory = (WSDLFactoryImpl)
		// WSDLPlugin.INSTANCE.createWSDL4JFactory();
		// WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
		// // wsdlReader.setFeature("javax.wsdl.verbose", true);
		// // wsdlReader.setFeature("javax.wsdl.importDocuments", true);
		//        
		// // log.trace(wsdlReader.toString());
		//		
		// Definition definition =
		// wsdlReader.readWSDL("CustomerDataAccessService.wsdl");
		//		
		// // log.trace(definition.toString());
		//		
		// Map services = definition.getServices();
		// for (Object o : services.entrySet()) {
		// Entry entry = (Entry) o;
		// // log.trace("Key: " + entry.getKey().getClass());
		// // QName qName = (QName) entry.getKey();
		// //
		// // log.trace(qName.getPrefix() + ";"
		// // + qName.getLocalPart() + ";"
		// // + qName.getNamespaceURI());
		//			
		// // log.trace("Value: " + entry.getValue().getClass());
		// ServiceImpl service = (ServiceImpl) entry.getValue();
		// log.trace("Service: " + service.getQName().getLocalPart());
		//			
		// }
		//		
		// Map messages = definition.getMessages();
		// for (Object o : messages.entrySet()) {
		// // log.trace(o.getClass());
		//			
		// Entry entry = (Entry) o;
		// // log.trace("Key: " + entry.getKey().getClass());
		// // QName qName = (QName) entry.getKey();
		// // log.trace(qName.getPrefix() + ";"
		// // + qName.getLocalPart() + ";"
		// // + qName.getNamespaceURI());
		//			
		// // log.trace("Value: " + entry.getValue().getClass());
		// MessageImpl msgImpl = (MessageImpl) entry.getValue();
		// qName = msgImpl.getQName();
		// // log.trace(qName.getPrefix() + ";"
		// // + qName.getLocalPart() + ";"
		// // + qName.getNamespaceURI());
		// log.trace("Message: " + qName.getLocalPart());
		// }
		//		
		// Map portTypes = definition.getPortTypes();
		// for (Object o : portTypes.entrySet()) {
		// Entry entry = (Entry) o;
		// PortTypeImpl portType = (PortTypeImpl) entry.getValue();
		// qName = portType.getQName();
		// log.trace("PortType: " + qName.getLocalPart());
		//			
		// List operations = portType.getOperations();
		// for (Object oo : operations) {
		// OperationImpl operation = (OperationImpl) oo;
		// log.trace("  Operation: " + operation.getName());
		// }
		// }

		// partner link types of the service?

		// BPELResourceSetImpl resourceSet2 = new BPELResourceSetImpl();
		//		
		// BPELResourceFactoryImpl bpelResourceFactory2 = new
		// BPELResourceFactoryImpl();
		// resourceSet2.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*",
		// bpelResourceFactory2);
		// //
		// // WSDLResourceFactoryImpl wsdlResourceFactory = new
		// WSDLResourceFactoryImpl();
		// //
		// resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*",
		// // wsdlResourceFactory);
		//		
		//		
		// BPELResource resource2 = (BPELResource)
		// resourceSet2.createResource(uri2);
		//		
		// Resource.Factory resourceFactory2 =
		// resourceSet2.getResourceFactoryRegistry().getFactory(uri, null);
		// log.trace("Using " + resourceFactory2.getClass() + " to load " +
		// uri2);
		//		
		// resource2.load(null);
		//		
		// for (TreeIterator iter = resource2.getAllContents();
		// iter.hasNext(); )
		// {
		// Object o = iter.next();
		//			
		// log.trace(o.getClass());
		//			
		// if (o instanceof UnknownExtensibilityElementImpl) {
		//				
		// UnknownExtensibilityElementImpl ue =
		// (UnknownExtensibilityElementImpl) o;
		//				
		// log.trace(ue.toString());
		// }
		// // log.trace(o.toString());
		// }

	}

	private static void dumpPartnerLinks(Logger log,
			org.eclipse.bpel.model.Process p) {
		log.trace("");
		log.trace("****************** PartnerLinks ******************");

		PartnerLinks plinks = p.getPartnerLinks();
		for (TreeIterator iter = plinks.eAllContents(); iter.hasNext();) {
			PartnerLink plink = (PartnerLink) iter.next();
			log.trace("PartnerLink: " + plink.getName());

			PartnerLinkType pLinkType = plink.getPartnerLinkType();
//			log.trace("PartnerLinkType: " + pLinkType.getName());
			log.trace("PartnerLinkType isProxy(): " + pLinkType.eIsProxy());

			if (pLinkType.eIsProxy()) {
				URI proxyURI = ((InternalEObject) pLinkType).eProxyURI();
				log.trace("ProxyURI: " + proxyURI);
			}
			
			EList roles = pLinkType.getRole();
			log.trace("Amount of roles: " + roles.size());

			for (Iterator roleIter = roles.iterator(); roleIter.hasNext();) {
				Role role = (Role) roleIter.next();
				log.trace("Role name: " + role.getName());

				PortTypeImpl portType = (PortTypeImpl) role.getPortType();

//				log.trace(portType);

				QName qName = portType.getQName();
				log.trace("PortType: " + qName.getLocalPart());
				
				List operations = portType.getOperations();
				log.trace("Amount of operations: " + operations.size());

				// Iterator iterIter = operations.iterator();
				// for (Object oo : operations) {
				for (Iterator iterIter = operations.iterator(); iterIter
						.hasNext();) {
					OperationImpl operation = (OperationImpl) iterIter.next();
					log.trace("  Operation: " + operation.getName());
					
					javax.wsdl.Input input = operation.getInput();
		            if (null != input) {
		              log.trace("InputMessage: " + input.getMessage().getQName());
		            }
		            
		            javax.wsdl.Output output = operation.getOutput();
		            if (null != output) {
		              log.trace("OutputMessage: " + output.getMessage().getQName());
		            }
				}
			}
			
			log.trace("");
		}
	}

	private static void dumpProcess(Logger log, org.eclipse.bpel.model.Process p) {
		log.trace("");
		log.trace("****************** Processes ******************");
		log.trace("name: " + p.getName());
		log.trace("suppressJoinFailure: " + p.isSetSuppressJoinFailure());
		log.trace("exitOnStandardFault: " + p.getExitOnStandardFault());
		
		Activity a = p.getActivity();
		log.trace("Activity: " + a.getName() + " Type: " + a.getClass());
		
		BPELSwitch bpelSwitch = new BPELSwitch();
		Object o = bpelSwitch.doSwitch(a);
		
		log.trace(o);
	}

	/**
	 * Possible variable declarations:
	 * 
	 * <!-- variable maps to XSD simple type -->
	 * <variable name="discount" type="xsd:string"/>
	 * 
	 * <!-- variable maps to XSD complex type -->
	 * <variable name="orderInfo" element="client:orderInfoType"/>
	 * 
	 * <!-- variable maps to WSDL message -->
	 * <variable name="inputVariable"
     *           messageType="client:RentalProcessRequestMessage"/> 
	 * @throws TransformerException 
	 */
	private static void dumpVariables(Logger log,
			org.eclipse.bpel.model.Process p) throws TransformerException {

		log.trace("");
		log.trace("****************** Variables ******************");

		Variables variables = p.getVariables();

		for (TreeIterator iter = variables.eAllContents(); iter.hasNext();) {
			Variable var = (Variable) iter.next();
			log.trace("Variable: " + var.getName() + " in " + var.eResource().getURI());

			org.w3c.dom.Element domElement = var.getElement();
			ElementNSImpl element = (ElementNSImpl) domElement;

			log.trace(DOMNode2String(element));
			
			handleMessageType(log, var);
			
			XSDTypeDefinition xsdType = var.getType();
			dumpXSDTypeDefinition(log, xsdType);
			
			XSDElementDeclaration xsdElement = var.getXSDElement();
			dumpXSDElementDeclaration(log, xsdElement);

			log.trace("");
		}
	}
	
	private static String DOMNode2String(org.w3c.dom.Element element) throws TransformerException {
		// Print the DOM node
		StringWriter sw = new StringWriter();
		StreamResult result = new StreamResult(sw);
		DOMSource source = new DOMSource(element);
		trans.transform(source, result);
		return sw.toString();
	}

	private static void dumpXSDTypeDefinition(Logger log,
			XSDTypeDefinition xsdType) {
		
		if (null == xsdType) {
			return;
		}
		log.trace("Type: " + xsdType.getName());
		
	}

	private static void handleMessageType(Logger log, Variable var) throws TransformerException {
		Message msg = var.getMessageType();
		
		if (null == msg) {
			return;
		}
		
		log.trace("Variable message type: " + msg + " in " + msg.eResource().getURI());
		log.trace(DOMNode2String(msg.getElement()));
		
		log.trace("isProxy: " + msg.eIsProxy());

//		QName qName = msg.getQName();
//		log.trace("Message qualified name: " + qName);
		
		log.trace("Amount of parts: " + msg.getParts().size());
		for (Iterator partIter = msg.getParts().entrySet().iterator(); partIter
				.hasNext();) {

			Entry entry = (Entry) partIter.next();
			Part part = (Part) entry.getValue();

			log.trace("Partname: " + part.getName());
			log.trace("Typename: " + part.getTypeName());
			log.trace("Part ElementName: " + part.getElementName());

			// XSD simple types do not have a element declaration, only
			// process it if it is present
			XSDElementDeclaration elementDecl = part.getElementDeclaration();
			dumpXSDElementDeclaration(log, elementDecl);
		}
	}

	/**
	 * If a variable is defined via a message, the message contains parts, each
	 * part contains an XML element which is of a certain XSD type. This method
	 * dumps the XSD declaration of the element
	 * @throws TransformerException 
	 */
	private static void dumpXSDElementDeclaration(Logger log,
			XSDElementDeclaration elementDecl) throws TransformerException {
		
		if (null == elementDecl) {
			return;
		}
		
		log.trace("ElementDeclaration name: " + elementDecl.getName() + " in " + elementDecl.eResource().getURI());
		log.trace(DOMNode2String(elementDecl.getElement()));
		
		XSDTypeDefinition typeDef = elementDecl.getType();
		log.trace("XSDTypeDefinition: in " + typeDef.eResource().getURI());
		log.trace(DOMNode2String(typeDef.getElement()));
		
		if (null != typeDef) {
			log.trace("ElementDeclaration type: " + typeDef.getName());

			XSDParticle particle = elementDecl.getType().getComplexType();
			
			if (null != particle) {
				// org.w3c.dom.Element element =
				// particle.getContent().getElement();
				EList<EObject> contents = particle.getContent().eContents();
				for (Iterator contentIter = contents.iterator(); contentIter
						.hasNext();) {
					XSDParticleImpl o = (XSDParticleImpl) contentIter.next();
					XSDElementDeclarationImpl e = ((XSDElementDeclarationImpl) o
							.getTerm());
					// typedefinitions are either the simple types (xsd:string,
					// xsd:integer, ...)
					// or the complex types defined in the schema
					log.trace(e.getName() + " "
							+ e.getTypeDefinition().getName());
				}
			}
			
			
			XSDSimpleTypeDefinition simpleDef = elementDecl.getType().getSimpleType();
			if (null != simpleDef) {
				log.trace("SimpleTypeName: " + simpleDef.getName());
			}
		} else {
			log.trace("Element without type!");
		}
	}

}
